package conMgr.ui.util;

import javax.swing.JLabel;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

/**
 * Provides a listener that updates a label in response to a slider value
 * change.
 * @author is4@uw.edu
 */
public class SliderChangeListener implements ChangeListener
{
	/**
	 * The label to update.
	 */
	private final JLabel label;
	
	/**
	 * The source slider.
	 */
	private final JSlider slider;
	
	/**
	 * Initializes a new slider change listener.
	 * @param slider The source slider.
	 * @param label The label to update.
	 */
	public SliderChangeListener(final JSlider slider, final JLabel label)
	{
		this.slider = slider;
		this.label = label;
	}
	
	/**
	 * Handles the state changed event.
	 */
	@Override
	public void stateChanged(ChangeEvent arg0)
	{
		label.setText(Integer.toString(slider.getValue()));
	}
}
